<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String title = "信息综合系统";
%>
<%@ include file="/WEB-INF/jsp/header.jsp"%>
<title><%=title%>-货票管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-touch-fullscreen" content="no" />
<meta content="telephone=no" name="format-detection" />
<meta name="apple-mobile-web-app-capable" content="no" />
</head>

<body class="fixed-top" style="background: #fff;">
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12" style="border-bottom:0px solid #4A8BC2">
				<ul class="breadcrumb" style="padding-bottom: 12px;background: #fff;">
					<li><a href="${pageContext.request.contextPath}/user/index.do" >
						 <i class="icon-angle-left"></i>
						 <i class="icon-angle-left"></i> &nbsp;&nbsp;
						 首页控制台</a>
						<span class="divider">/</span>
					</li>
					<li class="active">
					货票申请管理
					</li>
					<li class="pull-right search-wrap">
					<button
					 onclick="toggleCondi();" 
					 class="btn dropdown-toggle" data-toggle="dropdown">
								<span id="but_text">隐藏筛选区域</span> <i id="toggleCondi_i" class="icon-angle-up"></i>
					</button>
					&nbsp;&nbsp;
					<div class="btn-group pull-right">
						<button class="btn dropdown-toggle" data-toggle="dropdown">
							更多 <i class="icon-angle-down"></i>
						</button>
						<ul class="dropdown-menu pull-right">
							<li><a
								href="${pageContext.request.contextPath}/cargo/download.do">下载已筛选的货票申请</a></li>
							<c:if test="${hobby=='深圳发货岗'}">
							     <li><a href="#" onclick="showOpen(0,'新增');">新增一条货票申请</a></li>
							</c:if>
						</ul>
					</div></li>
				</ul>
			</div>
		</div>
		
		<!-- 查询过滤时的表单数据 -->
		<div class="widget">
			<div class="row-fluid">
				<div class="clearfix">
					<form id="filterForm">
						<input type="text" name="deliveryApplyTime" class="Wdate"
							style="width: 120px;" placeholder="发货申请日期"
							onMouseOver="this.title='发货申请日期'"
							onfocus="WdatePicker({isShowClear:true,readOnly:false,dateFmt:'yyyy/MM/dd'})" />

						<input type="text" class="span2" id="space" name="space"
							placeholder="申请发货片区" data-provide="typeahead"
							onMouseOver="this.title='申请发货片区'" data-items="4" /> 
						<input
							type="text" class="span2 typeahead" name="mgr"
							onMouseOver="this.title='申请发货经理'" id="mgr" placeholder="申请发货经理"
							data-provide="typeahead" data-items="4" /> 
						<input type="text"
							class="span2 typeahead" name="client" id="client"
							placeholder="客户" data-provide="typeahead"
							onMouseOver="this.title='客户'" data-items="4" /> 
						<input
							type="text" class="span2 typeahead" name="kaipiaodanwei"
							onMouseOver="this.title='开票单位'" id="kaipiaodanwei"
							placeholder="开票单位" data-provide="typeahead" data-items="4" /> 
						<input
							type="text" class="span2" name="chukudanhao"
							onMouseOver="this.title='出库单号'" id="outNumber" placeholder="出库单号" />
						<br> 
						<input type="text" name="kaipiaoTime"
							onMouseOver="this.title='开票日期'" class="Wdate"
							style="width: 120px;" placeholder="开票日期"
							onfocus="WdatePicker({isShowClear:true,readOnly:false,dateFmt:'yyyy/MM/dd'})" />

						<input type="text" class="span2" name="pici"
							onMouseOver="this.title='批次'" id="batchNumber" placeholder="批次" />

						<select id="product" name="product" multiple="multiple"
							onMouseOver="this.title='选择品种'" size="1"
							class="input-medium m-wrap">
							<option value="A">A</option>
							<option value="Y">Y</option>
							<option value="Z">Z</option>
						</select> 
						<select id="pack" onMouseOver="this.title='选择包装'" name="pack"
							multiple="multiple" size="1" class="input-medium m-wrap">
							<c:forEach items="${packs}" var="pack">
								<option value="${pack}">${pack}</option>
							</c:forEach>
						</select> <select onMouseOver="this.title='选择状态'" id="status" name="status"
							multiple="multiple" size="1" class="input-medium m-wrap">
							<c:forEach items="申请中,新疆已处理" var="s">
								<option value="${s}">${s}</option>
							</c:forEach>
						</select> 
						<input type="button" id="seach" name="seach" value="查询"
							class="btn  btn-primary" style="margin-bottom: 10px;"
							onclick="query(pNumber,pSize);"> 
						<input type="reset" id="reset"
							name="reset" value="重置该页面" class="btn  btn-primary"
							style="margin-bottom: 10px;" onclick="resetf();" />
					</form>
				</div>
			</div>

			<!-- 新增、更新时的表单数据 -->
			<div id="form_div" hidden>
				<div class="modal-body" style="height: 90%">
					<form method="post" id="submitForm">
						<input name="id" id="idU" hidden value="0">
						<table>
						  <tr>
						      <td><span>出库单号:</span></td>
						      <td>
						      <input type="text" class="span2 typeahead noNull sz"
                                    name="chukudanhao" id="chukudanhaoU" data-provide="typeahead"
                                    data-items="4"/>
                              </td>
                              
						      <td colspan="2"> 
						       历史出库单号：
						       <input type="text" class="span2 typeahead" style="background-color: yellow;"
                                    name="chukudanhao" id="chukudanhaoU_lx" data-provide="typeahead"
                                    data-items="4"/>
						      </td>
						       <td colspan="2"> 
						      <input type="button" value="出库单号联想数据" class="btn btn-small btn-success" id="association" 
						          onclick="checkRssociation(2);"/>   
						          
						     <input type="button" value="开票单位联想数据" class="btn btn-small btn-success" id="association" 
						          onclick="checkRssociation(3);"/>
						     <input type="button" value="客户联想数据" class="btn btn-small btn-success" id="association" 
						          onclick="checkRssociation(4);"/>
                              </td>
						  </tr>
						  <tr>
								<td><span>开票单位:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="kaipiaodanwei" id="kaipiaodanweiU"
									data-provide="typeahead" data-items="4" /></td>
								<td>
								<span>客户:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="client" id="clientU" data-provide="typeahead"
									data-items="4" /></td>
								<td>
								<span>品种:</span></td>
								<td>
								<select id="productU" name="product" size="1"
									onchange="fillMoney()"
									class="input-medium m-wrap noNull sz">
										<option value=""></option>
										<c:forEach items="${products}" var="product">
											<option value="${product}">${product}</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<td>
								<span>包装:</span></td>
								<td>
								<select id="packU" name="pack" 
									onchange="fillMoney()"
									class="input-medium m-wrap noNull sz">
										<option value=""></option>
										<c:forEach items="${packs}" var="pack">
											<option value="${pack}">${pack}</option>
										</c:forEach>
								</select></td>
							
								<td>数量:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz" 
									onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;);fillMoney();"
									name="count" id="countU" 
									data-provide="typeahead"
									data-items="4" placeholder="" />
								</td>
								<td>
								<span>件数:</span></td>
								<td>
								<select id="pcountU" name="pcount"
									class="input-medium m-wrap noNull sz">
										<option value=""></option>
										<option value="-1">散货</option>
										<c:forEach var="pcount" begin="1" end="100" varStatus="vs">
											<option value="${vs.count}">${vs.count}</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<td>开票价:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz" 
									onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('申请金额只能输入【数字】');this.value='';}"
									onkeyup="fillMoney();"
									name="kaipiaojia" id="kaipiaojiaU" data-provide="typeahead"
									data-items="4" /></td>
								<td>金额:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="money" id="moneyU" readonly="readonly"
									placeholder="双击我帮你填写" ondblclick="fillMoney()"
									data-provide="typeahead"
									data-items="4" /></td>
								<td><span>发货申请日期:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="deliveryApplyTime" id="deliveryApplyTimeU"
									data-provide="typeahead"
									onfocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy/MM/dd'})"
									data-items="4" /></td>
							</tr>
							<tr>
								<td>收货地址:</td>
								<td>
								<textarea rows="3" cols="150" name="goodsAddr"
										class="noNull sz" id="goodsAddrU"></textarea></td>
								<td>收货人:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="goodsMan" id="goodsManU" data-provide="typeahead"
									data-items="4" /></td>
								<td>收货电话:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="goodsPhone" id="goodsPhoneU" data-provide="typeahead"
									data-items="4" /></td>
							</tr>
							<tr>
								<td>条线:</td>
								<td>
								<select id="tiaoxiangU" name="tiaoxiang"
									class="input-medium m-wrap noNull sz">
										<option value=""></option>
										<c:forEach items="${txs}" var="tx">
											<option value="${tx}">${tx}</option>
										</c:forEach>
								</select></td>
								<td>票折金额:</td>
                                <td>
                                <input type="text" class="span3 typeahead noNull sz"
                                    name="pzmoney" id="pzmoneyU" value="0.0"
                                    placeholder="" 
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('票折金额只能输入【数字】');this.value='';}"
                                    data-provide="typeahead"    
                                    data-items="4" /></td>
								<td>付款记录:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
                                    name="payNote" id="payNoteU" 
                                    placeholder="" 
                                    data-provide="typeahead"    
                                    data-items="4" />
                                    
								<%-- <select style="width: 230px" id="payNoteU"
									name="payNote" class="input-medium m-wrap noNull sz">
										<option value=""></option>
										<c:forEach items="赊货,现款,账期" var="pay">
											<option value="${pay}">${pay}</option>
										</c:forEach>
								</select> --%>
								</td>
							</tr>
							<tr>
								<!-- <td><span>申请发货片区:</span></td>
								<td> 
								<input type="text" class="span3 typeahead noNull"
									name="space" id="spaceU" data-provide="typeahead"
									data-items="4" /></td>-->
								<td><span>申请发货经理:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="mgr" id="mgrU" data-provide="typeahead" data-items="4" />
								</td>

								<td>发货备注:</td>
								<td>
								<textarea rows="3" cols="150" name="deliveryDemo" class="sz"
										id="deliveryDemoU"></textarea></td>
								<td><span style="color: green;">发票快递号:</span></td>
                                <td>
                                <input type="text" class="span3 typeahead noNull xj"
                                    name="kaipiaoNo" id="kaipiaoNoU" data-provide="typeahead"
                                    data-items="4" /></td>
							</tr>
							<tr>
								<td><span style="color: green;">发货物流:</span></td>
								<td>
								<select style="width: 230px" id="deliveryWuliuU"
									name="deliveryWuliu" class="input-medium m-wrap noNull xj">
										<option value="中铁">中铁</option>
										<option value="空运">空运</option>
								</select></td>
								<td><span style="color: green;">发货物流单号:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull xj"
									name="deliveryDanhao" id="deliveryDanhaoU"
									data-provide="typeahead" data-items="4" /></td>
								<td><span style="color: green;">发票号码:</span></td>
                                <td><input type="text" class="span3 typeahead noNull xj"
                                    name="ticketNumber" id="ticketNumberU" data-provide="typeahead"
                                    data-items="4" /></td>
							</tr>

							<tr>
								<td>是否货票同行:</td>
								<td>
								<select style="width: 230px" id="hasHuopiaotongxingU"
									name="hasHuopiaotongxing" class="input-medium m-wrap noNull sz">
										<option value=""></option>
										<c:forEach items="是,否" var="has">
											<option value="${has}">${has}</option>
										</c:forEach>
								</select></td>
								<td><span>开票申请日期:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="kaipiaoApplyTime" id="kaipiaoApplyTimeU"
									data-provide="typeahead"
									onfocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy/MM/dd'})"
									data-items="4" /></td>
								<td>收票地址:</td>
								<td>
								<textarea rows="3" cols="150" name="ticketAddr"
										class="noNull sz" id="ticketAddrU"></textarea></td>
							</tr>
							<tr>
								<td>收票人:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="ticketMan" id="ticketManU" data-provide="typeahead"
									data-items="4" /></td>
								<td>收票电话:</td>
								<td>
								<input type="text" class="span3 typeahead noNull sz"
									name="ticketIphone" id="ticketIphoneU" data-provide="typeahead"
									data-items="4" /></td>
								<td><span style="color: green;">开票日期:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull xj"
									name="kaipiaoTime" id="kaipiaoTimeU" data-provide="typeahead"
									onfocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy/MM/dd'})"
									data-items="4" /></td>
							</tr>
							<tr>

								<td><span>批次:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull sz" 
									name="pici" id="piciU" data-provide="typeahead" data-items="4" />
								</td>
								
								<td><span style="color: green;">小批号:</span></td>
								<td>
								<input type="text" class="span3 typeahead noNull xj"
									name="smallPici" id="smallPiciU" data-provide="typeahead" data-items="4" />
								</td>
								
								<td>开票备注:</td>
								<td>
								<textarea rows="3" cols="150" placeholder="双击我帮你填写"
										ondblclick="fillKaipiaoDemo()" name="kaipiaoDemo"
										id="kaipiaoDemoU"></textarea></td>
										
							</tr>
						</table>
					</form>
				</div>
			</div>

			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN ALERTS PORTLET-->
					<div class="widget blue">
						<div class="widget-title">
							<h4>
								<i class="icon-reorder"></i>
								<a href="javascript:;" onclick="scrollToLeft();" title="定位到表格最左端" style ="color:white;">最左</a>
				                <a href="javascript:;" onclick="scrollToCenter();" title="定位到表格正中间" style ="color:white;">居中</a>
				                <a href="javascript:;" onclick="scrollToRight();" title="定位到表格最右端" style ="color:white;">最右</a>
							</h4>
							<span class="tools"> <a href="javascript:;"
								class="icon-chevron-down"></a>
							</span>
						</div>

						<div class="widget-body" style="overflow: auto" id="canvas-wrap">
							<div class="pageBottom" style="text-align: center;">
								<input type="hidden" id="page-size" value="0" />
								<div id="callBackPager" class="paging_bootstrap pagination"></div>
							</div>
							<table class="table table-striped table-hover table-bordered"
								width="640px;" style="table-layout: fixed">
								<thead>
									<tr>
										<th width="80px">开票单位</th>
										<th width="80px">客户</th>
										<th width="60px">品规/件数/数量</th>
										<th width="40px">开票价</th>
										<th width="40px">金额</th>
										<th width="54px">发货申请日期</th>
										<th width="170px">收货地址</th>
										<th width="150px">收货人/收货电话</th>
										<th width="60px">批次</th>
										<th width="60px">小批号</th>
										<th width="70px">票折金额</th>
										<th width="60px">付款记录</th>
										<th width="60px">出库单号</th>
										<th width="30px">发货物流</th>
										<th width="60px">发货物流单号</th>
										<th width="40px">条线</th>
										<th width="40px">有无流向</th>
										<th width="170px">发货备注</th>
										<th width="40px">是否货票同行</th>
										<th width="54px">开票申请日期</th>
										<th width="170px">收票地址</th>
										<th width="90px">收票人/收票电话</th>
										<th width="70px">开票日期</th>
										<th width="60px">发票号码</th>
										<th width="60px">发票快递号</th>
										<th width="170px">开票备注</th>
										<th width="50px">申请发货片区</th>
										<th width="50px">申请发货经理</th>
										<th width="50px">制单人</th>
									</tr>
								</thead>
								<tbody id="distribute-body">
								</tbody>
							</table>
						</div>
					</div>
					<!-- END ALERTS PORTLET-->
				</div>
			</div>
		</div>
		<!-- END BASIC PORTLET-->
	</div>


	<!-- BEGIN JAVASCRIPTS -->
	<!-- Load javascripts at bottom, this will reduce page load time -->
	<script src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.nicescroll.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js" type="text/javascript" ></script>
	<script src="${pageContext.request.contextPath}/js/jquery.slimscroll.min.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.easy-pie-chart.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.sparkline.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/Chart.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.scrollTo.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/common-scripts.js"></script>

	<!-- start layer -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
	<!-- end layer  -->

	<!-- start 多选下拉，并具备过滤功能 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap-multiselect.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap-multiselect.css" type="text/css" />
	<!-- end 多选下拉，并具备过滤功能 -->

	<!-- start 自动补全 -->
	<script src="${pageContext.request.contextPath}/js/bootstrap-typeahead.js"></script>
	<!-- end 自动补全 -->

	<!-- start 分页插件 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/extendPagination.js"></script>
	<!-- end 分页插件 -->

	<!-- start 日期插件 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
	<!-- end 日期插件 -->


	<!-- 自定义的script方法 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/javascript/httpService.js"></script>

	<!-- 查询条件相关 -->
	<script type="text/javascript">
		$(document).ready(function() {
			
			//自动补全 填写数据源
			var mgrs = ${mgrs};
			$('#mgr').typeahead({
				source : mgrs
			});
			var clientList = ${clientList};
			$('#client').typeahead({
				source : clientList
			});
			var spaces = ${spaces};
			$('#space').typeahead({
				source : spaces
			});
			var kaipiaodanwei = ${kaipiaodanwei};
			$('#kaipiaodanwei').typeahead({
				source : kaipiaodanwei
			});

			//多选下拉，并具备过滤功能 填写数据源
			$('#product').multiselect({
				includeSelectAllOption : true,
				nonSelectedText : '请选择品种',
				enableFiltering : true,
				maxHeight : 300,
				buttonWidth : '100px'
			});
			$('#pack').multiselect({
				includeSelectAllOption : true,
				nonSelectedText : '请选择包装',
				enableFiltering : true,
				maxHeight : 300,
				buttonWidth : '100px'
			});
			$('#status').multiselect({
				includeSelectAllOption : true,
				nonSelectedText : '请选择状态',
				enableFiltering : true,
				maxHeight : 300,
				buttonWidth : '100px'
			});
		});
	</script>

	<!-- 查询显示list -->
	<script type="text/javascript">
		function query(pageNumber, pageSize) {
			//查询后，隐藏查询区域
			//toggleCondi_hidden();
			var url = "${pageContext.request.contextPath }/cargo/selectForList.do?pageNumber="
					+ pageNumber + "&pageSize=" + pageSize;
			var params = $("#filterForm").serialize();
	    	queryList(url,params);
		}

		//动态填充table 列表数据
		function createTable(currPage, limit, total, items) {
			var html = [], showNum = limit;
			if (total - (currPage * limit) < 0)
				showNum = total - ((currPage - 1) * limit);
			for (var i = 0; i < showNum; i++) {
				html.push("<tr ondblclick=\"showOpen('" + items[i].id+ "','修改')\" >");
				html.push('<td>' + formatData(items[i].kaipiaodanwei)+ '</td>');
				html.push('<td>' + formatData(items[i].client) + '</td>');
				html.push('<td>' + formatData(items[i].product)
						+ formatData(items[i].pack) + "/"
						+ formatData(items[i].pcount) + "件/ "
						+ formatData(items[i].count) + '</td>');
				html.push('<td>' + formatData(items[i].kaipiaojia) + '</td>');
				html.push('<td>' + formatData(items[i].money) + '</td>');
				html.push('<td>'+ formatDate(formatData(items[i].deliveryApplyTime))+ '</td>');
				html.push('<td>' + formatData(items[i].goodsAddr) + '</td>');
				html.push('<td>' + formatData(items[i].goodsMan) + "/"+ formatData(items[i].goodsPhone) + '</td>');
				html.push('<td style="word-wrap:break-word;word-break:break-all;">'+ formatData(items[i].pici) + '</td>');
				html.push('<td>' + formatData(items[i].smallPici) + '</td>');
				html.push('<td>' + formatData(items[i].pzmoney) + '</td>');
				html.push('<td>' + formatData(items[i].payNote) + '</td>');
				html.push('<td>' + formatData(items[i].chukudanhao) + '</td>');
				html.push('<td>' + formatData(items[i].deliveryWuliu)+ '</td>');
				html.push('<td style="word-wrap:break-word;word-break:break-all;">' + formatData(items[i].deliveryDanhao)+ '</td>');
				html.push('<td>' + formatData(items[i].tiaoxiang) + '</td>');
				html.push('<td>' + formatData(items[i].hasPlans) + '</td>');
				html.push('<td>' + formatData(items[i].deliveryDemo) + '</td>');
				html.push('<td>' + formatData(items[i].hasHuopiaotongxing)+ '</td>');
				html.push('<td>'+ formatDate(formatData(items[i].kaipiaoApplyTime))+ '</td>');
				html.push('<td>' + formatData(items[i].ticketAddr) + '</td>');
				html.push('<td style="word-wrap:break-word;word-break:break-all;">' + formatData(items[i].ticketMan) + "/"+ formatData(items[i].ticketIphone) + '</td>');
				html.push('<td>' + formatDate(formatData(items[i].kaipiaoTime))+ '</td>');
				html.push('<td style="word-wrap:break-word;word-break:break-all;">' + formatData(items[i].ticketNumber) + '</td>');
				html.push('<td style="word-wrap:break-word;word-break:break-all;">' + formatData(items[i].kaipiaoNo) + '</td>');
				html.push('<td>' + formatData(items[i].kaipiaoDemo) + '</td>');
				html.push('<td>' + formatData(items[i].space) + '</td>');
				html.push('<td>' + formatData(items[i].mgr) + '</td>');
				html.push('<td>' + formatData(items[i].dataer) + '</td>');
				html.push('</tr>');
			}
			var mainObj = $('#distribute-body');
			mainObj.empty();
			mainObj.html(html.join(''));
		};
	</script>

	<!-- 新增、更新相关 -->
	<script>
		//件数定义
		var p400 = 400;
		var p300 = 300;
		var p200 = 200;
		var p320 = 320;
		var p50 = 50;
		var hobby = "<%=session.getAttribute("hobby")%>";    
        if(hobby=='深圳发货岗'){     
            $("#submitForm").find(".xj").attr("readonly","readonly");
        }else if(hobby=='新疆发货岗'){                   
            $("#submitForm").find(".sz").attr("readonly","readonly");           
            $("#submitForm").find(".sz").attr("disabled","disabled");           
        }          
		var htmls = $("#form_div").html();
		var uploadFileHtml = $("#uploadFileForm").html();
		var ret = null;
		var action = null;
		var open = false;
		
		function checkByHobby(formId){
			//获取到session中的hobby
			var hobby = "<%=session.getAttribute("hobby")%>"; 
			var noNull = [];
			var address = "null";
			if(hobby=='深圳发货岗'){
				noNull = $("#"+formId+"").find(".sz");
				address = "深圳";
			}else if(hobby=='新疆发货岗'){
				noNull = $("#"+formId+"").find(".xj");
				address = "新疆";
			}
			console.log(noNull);
			for(var i=0;i<noNull.length;i++){
		        if(noNull[i].value==null||noNull[i].value==undefined||noNull[i].value==""){
		            layer.msg(address+"存在未填写项，请完善！");
		            return "false";
		        }
		    }
			return "true";
		}
		//联想数据
		function checkRssociation(type){
			var chukudanhao = $("#chukudanhaoU_lx").val();
			var kaipiaodanwei = $("#kaipiaodanweiU").val();
			var client = $("#clientU").val();
			sendRequest("${pageContext.request.contextPath }/cargo/checkRssociation.do?type="+type, 
					{chukudanhao:chukudanhao,kaipiaodanwei:kaipiaodanwei,client:client}, 
				function(result) {
                var code = result.code;
                if(code==1){
                	var cargo = result.msg;
                	$("#packU").val(cargo.pack);
                	$("#pcountU").val(cargo.pcount);
                	$("#countU").val(cargo.count);
                	$("#kaipiaodanweiU").val(cargo.kaipiaodanwei);
                	$("#clientU").val(cargo.client);
                	$("#productU").val(cargo.product);
                	$("#kaipiaojiaU").val(cargo.kaipiaojia);
                    $("#moneyU").val(cargo.money);
                    $("#goodsAddrU").val(cargo.goodsAddr);
                    $("#goodsManU").val(cargo.goodsMan);
                    $("#goodsPhoneU").val(cargo.goodsPhone);
                    $("#piciU").val(cargo.pici);
                    $("#smallPiciU").val(cargo.smallPici);
                    $("#payNoteU").val(cargo.payNote);
                    //$("#chukudanhaoU").val(cargo.chukudanhao);
                    $("#deliveryDemoU").val(cargo.deliveryDemo);
                    $("#kaipiaoDemoU").val(cargo.kaipiaoDemo);
                    //$("#deliveryWuliuU").val(cargo.deliveryWuliu);
                    //$("#deliveryDanhaoU").val(cargo.deliveryDanhao);
                    $("#tiaoxiangU").val(cargo.tiaoxiang);
                    $("#hasPlansU").val(cargo.hasPlans);
                    $("#hasHuopiaotongxingU").val(cargo.hasHuopiaotongxing);
                    $("#ticketAddrU").val(cargo.ticketAddr);
                    $("#ticketManU").val(cargo.ticketMan);
                    $("#ticketIphoneU").val(cargo.ticketIphone);
                    //$("#ticketNumberU").val(cargo.ticketNumber);
                    //$("#kaipiaoNoU").val(cargo.kaipiaoNo);
                    $("#dataerU").val(cargo.dataer);
                    $("#mgrU").val(cargo.mgr);
                } else if (code == -1) { // 有错误
                	$("#chukudanhaoU").val("");
                    //$("#chukudanhaoU").focus();
                    layer.alert(result.msg);
                }else{
                	open = true;
                    layer.msg(result.msg);
                }
            });	
		}
		
		//type:新增、修改
		function showOpen(id, type) {
			$("#form_div").remove();
           
			//不管是新增还是修改，都要打开这个对话框
			layer.open({
				title : [ type + '【发货、开票申请】', 'font-size:18px;' ],
				type : 1,
				content : htmls, //这里content是一个普通的String
				btn : ['保存并继续','删除', '取消' ],
				yes : function(index, layero) {
					var ret = checkByHobby("submitForm");
					if (ret == "false") {
						open = true;
						return open;
					}
					layer.load(2);
					if ("新增" == type) {
						action = "${pageContext.request.contextPath }/cargo/saveOrUpdate.do?flag=N";
						open = true;
					} else if ("修改" == type) {
						action = "${pageContext.request.contextPath }/cargo/saveOrUpdate.do?flag=E";
					}
					var params = $("#submitForm").serialize();
					sendRequest(action, params, function(result) {
						var code = result.code;
						if (code == -2) { //excel校验不通过
							open = true;
							layer.msg(result.msg);
						} else if (code == -1) { // 有错误
							layer.alert(result.msg);
						} else if (code > 0) {
							if ("修改" == type) {
								layer.closeAll();
								query(pNumber, pSize);
							} else {
								$("#moneyU").val("");
							}
							layer.alert(result.msg);
						}
					});
					return open;
				},
				
				btn2 : function(index, layero) {
					//询问框
					layer.confirm('确定要删除吗？', {
					  btn: ['确定','取消'] //按钮
					}, function(){
						var url = "${pageContext.request.contextPath }/cargo/deleteByID.do";
						sendRequest(url,{"id" : id},function(result) {
							var code = result.code;
							if (code == -1) { // 有错误
								layer.alert(result.msg);
							} else if (code > 0) {
								//layer.alert(result.msg);
								layer.msg(result.msg, {icon: 1});
								layer.closeAll();
								query(pNumber, pSize);
							}
						});
					}, function(){
						layer.msg('已取消操作', {icon: 1});
					});
					return false;
				}, 
				cancel : function() {
				},
				area : [ '1100px', '630px' ]
			//调整弹出框的长宽
			});

			if ("修改" == type) {
				var url = "${pageContext.request.contextPath }/cargo/selectByID.do";
				sendRequest(url,{"id" : id},function(result) {
					var code = result.code;
					var ret = result.msg;
					if (code > 0) {
						$("#idU").val(ret.id);
						$("#kaipiaodanweiU").val(ret.kaipiaodanwei);
						$("#clientU").val(ret.client);
						$("#productU").val(ret.product);
						$("#packU").val(ret.pack);
						$("#pcountU").val(ret.pcount);
						$("#countU").val(ret.count);
						$("#kaipiaojiaU").val(ret.kaipiaojia);
						$("#moneyU").val(ret.money);
						$("#deliveryApplyTimeU").val(formatDate(ret.deliveryApplyTime));
						$("#goodsAddrU").val(ret.goodsAddr);
						$("#goodsManU").val(ret.goodsMan);
						$("#goodsPhoneU").val(ret.goodsPhone);
						$("#piciU").val(ret.pici);
						$("#smallPiciU").val(ret.smallPici);
						$("#payNoteU").val(ret.payNote);
						$("#chukudanhaoU").val(ret.chukudanhao);
						$("#deliveryWuliuU").val(ret.deliveryWuliu);
						$("#deliveryDanhaoU").val(ret.deliveryDanhao);
						$("#tiaoxiangU").val(ret.tiaoxiang);
						$("#hasPlansU").val(ret.hasPlans);
						$("#deliveryDemoU").val(ret.deliveryDemo);
						$("#hasHuopiaotongxingU").val(ret.hasHuopiaotongxing);
						$("#kaipiaoApplyTimeU").val(formatDate(ret.kaipiaoApplyTime));
						$("#ticketAddrU").val(ret.ticketAddr);
						$("#ticketManU").val(ret.ticketMan);
						$("#ticketIphoneU").val(ret.ticketIphone);
						$("#kaipiaoTimeU").val(formatDate(ret.kaipiaoTime));
						$("#ticketNumberU").val(ret.ticketNumber);
						$("#kaipiaoNoU").val(ret.kaipiaoNo);
						$("#kaipiaoDemoU").val(ret.kaipiaoDemo);
						$("#spaceU").val(ret.space);
						$("#mgrU").val(ret.mgr);
						$("#dataerU").val(ret.dataer);
					}
				});
			}

			//给日期赋值默认值        
			var value = new Date().getFullYear()+'/'+(new Date().getMonth()+1) + '/' + new Date().getDate();
			$("#kaipiaoTimeU").val(value);   //开票日期
			$("#kaipiaoApplyTimeU").val(value);//开票申请日期
			$("#deliveryApplyTimeU").val(value);// 发货申请日期
			//自动补全 填充数据源
			var kaipiaodanwei = ${kaipiaodanwei};
			$('#kaipiaodanweiU').typeahead({
				source : kaipiaodanwei
			});
			var clientList = ${clientList};
			$('#clientU').typeahead({
				source : clientList
			});
			var spaces = ${spaces};
			$('#spaceU').typeahead({
				source : spaces
			});
			var mgrs = ${mgrs};
			$('#mgrU').typeahead({
				source : mgrs
			});
		}

		//根据数量自动填充件数
		function fillCount() {
			//获取用户已经选择好的包装
			var product = $("#productU").val();
			var pack = $("#packU").val();
			var kaipiaojia = $("#kaipiaojiaU").val()
			var pcount = $("#pcountU").val();
			if(pcount == "-1" || pcount == ""){
				return;
			}
			
		}
		//自动填充金额
		function fillMoney() {
			var kaipiaojia = parseFloat($("#kaipiaojiaU").val());
			var count = parseFloat($("#countU").val());
			if(kaipiaojia>=0 && count>=0){
				var money = kaipiaojia * count;
	            $("#moneyU").val(money.toFixed(2));
	            var money = $("#moneyU").val();
	            if(money > 116000){
	            	alert("开票金额不能大于116000元，请分单录入");
	            	$("#moneyU").val("");
	            }
			} else {
				 $("#moneyU").val("");
			}
			//获取用户已经选择好的包装
			var product = $("#productU").val();
			var pack = $("#packU").val();
			//自动填充件数
			if (product == "A") {
				if (pack == "20" || pack == "30" || pack == "40"|| pack == "24") {
					$("#pcountU").val(count/p400);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else if (pack == "36" || pack == "48") {
					$("#pcountU").val(count/p300);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else {
					$("#pcountU").val(-1);
				}
			}
			if (product == "Y") {
				if (pack == "20" || pack == "40") {
					$("#pcountU").val(count/p200);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else if (pack == "30" || pack == "24") {
					$("#pcountU").val(count/p400);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else if (pack == "36") {
					$("#pcountU").val(count/p320);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else {
					$("#pcountU").val(-1);
				}
			}
			if (product == "Z") {
				if (pack == "20" || pack == "30") {
					$("#pcountU").val(count/p300);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else if (pack == "24") {
					$("#pcountU").val(count/p200);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else if (pack == "48") {
					$("#pcountU").val(count/p400);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else {
					$("#pcountU").val(-1);
				}
			}
			if (product == "B") {
				if (pack == "5" || pack == "10") {
					$("#pcountU").val(count/p50);
					if($("#pcountU").val()=="" || $("#pcountU").val()=="undefine"){
						$("#pcountU").val(-1);
					}
				} else {
					$("#pcountU").val(-1);
				}
			}
		}
		//自动填充开票备注
		function fillKaipiaoDemo() {
			var h = $("#hasHuopiaotongxingU").val();
			var ph = $("#piciU").val().split("/");
			if (h == "是") {
				var note = "货票同行、发票备注批号" + ph[0] + "、生产日期" + ph[0] + "及效期";
			} else {
				var note = "暂不开发票，后期OA申请";
			}
			$("#kaipiaoDemoU").val(note);
		}
	</script>
</body>
</html>